package com.atguigu.gulimall.order.listener;

import com.atguigu.gulimall.order.entity.OmsOrderItemEntity;
import com.atguigu.gulimall.order.service.OmsOrderService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @author ming
 * @create 2022/5/12
 * @description:
 */
@Slf4j
@Component
public class OrderCloseListener {
    @Autowired
    private OmsOrderService orderService;
    @RabbitListener(queues = "order.release.queue")
    public void listenOrderQueue(OmsOrderItemEntity order, Channel channel, Message message) throws IOException {
        try {
            log.info("*********开始关闭订单*******************");
            orderService.closeOrder(order);
            //手动调用支付宝收单
            
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
            e.printStackTrace();
        }



    }
}
